package beer.xz.beer.device.ui.loading

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp

@Composable
fun LoadingScreen(
    text: String, progress: Float, modifier: Modifier = Modifier
) {
    Box(
        modifier = modifier.fillMaxSize(), contentAlignment = Alignment.Center
    ) {
        Column(
            horizontalAlignment = Alignment.CenterHorizontally,
//            modifier = Modifier.border(1.dp, Color.Red)
        ) {
            Row(
                verticalAlignment = Alignment.Bottom
//                    .border(1.dp, Color.Blue)
            ) {
                CircularProgressIndicator(
                    color = Color.Green,
                    progress = { progress },
                    modifier = Modifier.size(100.dp),
                    strokeWidth = 15.dp
                )
            }
            Spacer(Modifier.height(20.dp))
            Row(
                verticalAlignment = Alignment.CenterVertically
//                    .border(1.dp, Color.Blue)
            ) {
                Text(
                    text = text,
                    color = Color.Red,
                    fontSize = TextUnit(30f, TextUnitType.Sp),
                    style = MaterialTheme.typography.headlineLarge
                )
            }
        }
    }
}


@Preview
@Composable
fun preview() {
    LoadingScreen(text = "Loading", progress = 0.5f)
}